// pages/order-detail/index.js
const {
  getOrderInfo,
  agreePrice,
  checkOrder,
} = require('../../apiConfig/apiList/luban')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    formData:{},
    disabled: true,
    textEnabled: false,
    orderId: '',
    loginType:'1',
  },
  handleAgree(){
    let that = this;
    let params = {
      id: this.data.orderId,
      status: '4',
      reason: '',
    };
    agreePrice(params).then(res=>{
      console.log(res)
      if(res.code == 200){
        wx.showToast({
          title: '同意报价成功',
          icon: 'success',
          mask: true,
          duration: 1500
        })
        that.backPage();
      }
    })
  },
  handlePass(e){
    let that = this;
    let value = e.currentTarget.dataset.value;
    let params = {
      id: this.data.orderId,
      status: value,
      reason: this.data.formData.reason,
    };
    checkOrder(params).then(res=>{
      if(res.code == 200){
        wx.showToast({
          title: `${value === '6' ? '验证通过' : '验证不通过'}`,
          icon: 'success',
          mask: true,
          duration: 1500
        })
        that.backPage();
      }
    }).catch(err=>{
      console.log('catch', err)
    })
  },
  backPage(){
    wx.redirectTo({
      url: '/pages/order-list/index',
    })
    // let pages = getCurrentPages(); 
    // let last = pages[pages.length - 2];
    // wx.navigateBack({
    //   delta: 1,
    //   success: function () {  
    //     console.log(1111111)
    //     if (last) {
    //       last.onShow;
    //       last.onShow();
    //       last.getOrderList();
    //       console.log('last.onShow', last)
    //     }  
    //   }  
    // });
  },
  getDetail(){
    let that = this;
    let params = {id: this.data.orderId}
    getOrderInfo(params).then(res=>{
      console.log(res)
      if(res.code == 200){
        that.setData({
          formData: res.data
        })
      }
    })
    const loginData = wx.getStorageSync('loginData');
    that.setData({
      loginType: loginData.loginType 
    })
 
  },
  getReason(e){
    this.setData({
      'formData.reason': e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    this.setData({
      orderId: options.id
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})